package com.chinaedu.oc.util.excel;

import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.util.HSSFColor;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;

/**
 * excel样式类
 * @Description: TODO
 * @author A18ccms a18ccms_gmail_com 
 * @date 2017年5月26日 下午12:06:28 
 *
 */
public class CellStyle {
	public static final int MODE_0 = 0;
	public static final int MODE_1 = 1;
	public static final int MODE_2 = 2;
	public static HSSFCellStyle getStyle(int mode, HSSFWorkbook workbook){
		switch(mode){
		case MODE_0: return getStyle1(workbook);
		case MODE_1: return getStyle2(workbook);
		case MODE_2: return getStyle3(workbook);
		default : return getStyle3(workbook);
		}
	}
	/**
	 * style1
	 * @param workbook
	 * @return
	 */
	private static HSSFCellStyle getStyle1(HSSFWorkbook workbook){
		HSSFCellStyle style = workbook.createCellStyle();  
		style.setFillForegroundColor(HSSFColor.SKY_BLUE.index);  
		style.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);  
		style.setBorderBottom(HSSFCellStyle.BORDER_THIN);  
		style.setBorderLeft(HSSFCellStyle.BORDER_THIN);  
		style.setBorderRight(HSSFCellStyle.BORDER_THIN);  
		style.setBorderTop(HSSFCellStyle.BORDER_THIN);  
		style.setAlignment(HSSFCellStyle.ALIGN_CENTER);  
		HSSFFont font = workbook.createFont();  
		font.setColor(HSSFColor.VIOLET.index);  
		font.setFontHeightInPoints((short) 12);  
		font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);  
		style.setFont(font); 

		return style;
	}
	/**
	 * style2
	 * @param workbook
	 * @return
	 */
	private static HSSFCellStyle getStyle2(HSSFWorkbook workbook){
		HSSFCellStyle style2 = workbook.createCellStyle();  
		style2.setFillForegroundColor(HSSFColor.LIGHT_YELLOW.index);  
		style2.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);  
		style2.setBorderBottom(HSSFCellStyle.BORDER_THIN);  
		style2.setBorderLeft(HSSFCellStyle.BORDER_THIN);  
		style2.setBorderRight(HSSFCellStyle.BORDER_THIN);  
		style2.setBorderTop(HSSFCellStyle.BORDER_THIN);  
		style2.setAlignment(HSSFCellStyle.ALIGN_CENTER);  
		style2.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);  
		HSSFFont font2 = workbook.createFont();  
		font2.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);  
		style2.setFont(font2);
		return style2;
	}
	/**
	 * style3
	 * @param workbook
	 * @return
	 */
	private static HSSFCellStyle getStyle3(HSSFWorkbook workbook){
		HSSFCellStyle cellStyle = workbook.createCellStyle();
		cellStyle.setBorderBottom(HSSFCellStyle.BORDER_THIN);
		cellStyle.setBottomBorderColor(HSSFColor.BLACK.index);
		cellStyle.setBorderLeft(HSSFCellStyle.BORDER_THIN);
		cellStyle.setLeftBorderColor(HSSFColor.BLACK.index);
		cellStyle.setBorderRight(HSSFCellStyle.BORDER_THIN);
		cellStyle.setRightBorderColor(HSSFColor.BLACK.index);
		cellStyle.setBorderTop(HSSFCellStyle.BORDER_THIN);
		cellStyle.setTopBorderColor(HSSFColor.BLACK.index);
		cellStyle.setAlignment(XSSFCellStyle.ALIGN_CENTER); // 居中
		cellStyle.setVerticalAlignment(XSSFCellStyle.ALIGN_CENTER);
		return cellStyle;
	}
}
